package com.zt.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                // 是否允许发送 Cookie
                .allowCredentials(true)
                // 允许所有来源
                .allowedOrigins("*")
                // 允许的请求方法
                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
                // 允许的请求头
                .allowedHeaders("*")
                // 暴露的响应头
                .exposedHeaders("Access-Control-Allow-Origin", "Content-Type", "Authorization");
    }
}